﻿/* ----------------------------------------------------------------------
Axiom UI
Copyright (C) 2017-2021 Matt McManis
https://github.com/MattMcManis/Axiom
https://axiomui.github.io
mattmcmanis@outlook.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.If not, see <http://www.gnu.org/licenses/>. 
---------------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModel;

namespace Controls.Audio.Codec
{
    public class PCM : Controls.IAudioCodec
    {
        // ---------------------------------------------------------------------------
        // Codec
        // ---------------------------------------------------------------------------
        public ObservableCollection<ViewModel.Audio.AudioCodec> codec { get; set; } = new ObservableCollection<ViewModel.Audio.AudioCodec>()
        {
             new ViewModel.Audio.AudioCodec() { Codec = "pcm_s24le", Parameters = "" }
        };

        public static String Codec_Set()
        {
            //PCM pcm = new PCM();

            switch (VM.AudioView.Audio_BitDepth_SelectedItem)
            {
                case "auto":
                    return "pcm_s24le";

                case "8":
                    return "pcm_u8";

                case "16":
                    return "pcm_s16le";

                case "24":
                    return "pcm_s24le";

                case "32":
                    return "pcm_f32le";

                case "64":
                    return "pcm_f64le";

                default:
                    return "pcm_s24le";
            }

            //PCM pcm = new PCM();

            //switch (VM.AudioView.Audio_BitDepth_SelectedItem)
            //{
            //    // auto
            //    case "auto":
            //        //PCM.codec.FirstOrDefault().Codec = "pcm_s24le";
            //        pcm.codec.FirstOrDefault(item => item.Codec).Codec = "pcm_s24le";
            //        break;
            //    // 8
            //    case "8":
            //        pcm.codec.FirstOrDefault(item => item.Codec == item.Codec).Codec = "pcm_u8";
            //        break;
            //    // 16
            //    case "16":
            //        pcm.codec.FirstOrDefault(item => item.Codec == item.Codec).Codec = "pcm_s16le";
            //        break;
            //    // 24
            //    case "24":
            //        pcm.codec.FirstOrDefault(item => item.Codec == item.Codec).Codec = "pcm_s24le";
            //        break;
            //    // 32
            //    case "32":
            //        pcm.codec.FirstOrDefault(item => item.Codec == item.Codec).Codec = "pcm_f32le";
            //        break;
            //    // 64
            //    case "64":
            //        pcm.codec.FirstOrDefault(item => item.Codec == item.Codec).Codec = "pcm_f64le";
            //        break;
            //}

            //// Combine Codec + Parameters
            //List<string> codec_parameters = new List<string>()
            //{
            //    "-c:a",
            //    PCM.codec.FirstOrDefault()?.Codec,
            //    PCM.codec.FirstOrDefault()?.Parameters
            //};

            //VM.AudioView.Audio_Codec = string.Join(" ", codec_parameters.Where(s => !string.IsNullOrEmpty(s)));
        }


        // ---------------------------------------------------------------------------
        // Items Source
        // ---------------------------------------------------------------------------

        // -------------------------
        // Stream
        // -------------------------
        // Doesn't Change, List Source in ViewModel

        // -------------------------
        // Channel
        // -------------------------
        public ObservableCollection<string> channel { get; set; } = new ObservableCollection<string>()
        {
            "Source",
            "Mono",
            "Stereo",
            "5.1"
        };

        // -------------------------
        // Quality
        // -------------------------
        public ObservableCollection<ViewModel.Audio.AudioQuality> quality { get; set; } = new ObservableCollection<ViewModel.Audio.AudioQuality>()
        {
            new ViewModel.Audio.AudioQuality() { Name = "Auto",     CBR_BitMode = "", CBR = "",    VBR_BitMode = "", VBR = "", NA = "" },
            new ViewModel.Audio.AudioQuality() { Name = "Lossless", CBR_BitMode = "",     CBR = "",    VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "320",      CBR_BitMode = "-b:a", CBR = "320", VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "256",      CBR_BitMode = "-b:a", CBR = "256", VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "224",      CBR_BitMode = "-b:a", CBR = "224", VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "192",      CBR_BitMode = "-b:a", CBR = "192", VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "160",      CBR_BitMode = "-b:a", CBR = "160", VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "128",      CBR_BitMode = "-b:a", CBR = "128", VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "96",       CBR_BitMode = "-b:a", CBR = "96",  VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "64",       CBR_BitMode = "-b:a", CBR = "64",  VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "Custom",   CBR_BitMode = "-b:a", CBR = "",    VBR_BitMode = "", VBR = ""   },
            new ViewModel.Audio.AudioQuality() { Name = "Mute",     CBR_BitMode = "",     CBR = "",    VBR_BitMode = "", VBR = ""   }
        };

        // -------------------------
        // Compression Level
        // -------------------------
        public ObservableCollection<string> compressionLevel { get; set; } = new ObservableCollection<string>()
        {
            "auto"
        };

        // -------------------------
        // Sample Rate
        // -------------------------
        public ObservableCollection<ViewModel.Audio.AudioSampleRate> sampleRate { get; set; } = new ObservableCollection<ViewModel.Audio.AudioSampleRate>()
        {
            new ViewModel.Audio.AudioSampleRate() { Name = "auto",     Frequency = "" },
            new ViewModel.Audio.AudioSampleRate() { Name = "8k",       Frequency = "8000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "11.025k",  Frequency = "11025" },
            new ViewModel.Audio.AudioSampleRate() { Name = "12k",      Frequency = "12000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "16k",      Frequency = "16000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "22.05k",   Frequency = "22050" },
            new ViewModel.Audio.AudioSampleRate() { Name = "24k",      Frequency = "24000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "32k",      Frequency = "32000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "44.1k",    Frequency = "44100" },
            new ViewModel.Audio.AudioSampleRate() { Name = "48k",      Frequency = "48000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "64k",      Frequency = "64000" },
            new ViewModel.Audio.AudioSampleRate() { Name = "88.2k",    Frequency = "88200" },
            new ViewModel.Audio.AudioSampleRate() { Name = "96k",      Frequency = "96000" }
        };

        // -------------------------
        // Bit Depth
        // -------------------------
        public ObservableCollection<ViewModel.Audio.AudioBitDepth> bitDepth { get; set; } = new ObservableCollection<ViewModel.Audio.AudioBitDepth>()
        {
            new ViewModel.Audio.AudioBitDepth() { Name = "auto", Depth = "" },
            new ViewModel.Audio.AudioBitDepth() { Name = "8",    Depth = "" },
            new ViewModel.Audio.AudioBitDepth() { Name = "16",   Depth = "" },
            new ViewModel.Audio.AudioBitDepth() { Name = "24",   Depth = "" },
            new ViewModel.Audio.AudioBitDepth() { Name = "32",   Depth = "" },
            new ViewModel.Audio.AudioBitDepth() { Name = "64",   Depth = "" }
        };


        // ---------------------------------------------------------------------------
        // Controls Behavior
        // ---------------------------------------------------------------------------

        // -------------------------
        // Selected Items
        // -------------------------
        public List<ViewModel.Audio.Selected> controls_Selected { get; set; } = new List<ViewModel.Audio.Selected>()
        {
            new ViewModel.Audio.Selected()
            {
                Quality = "Lossless",
                CompressionLevel = "auto"
            },
        };

        // -------------------------
        // Checked
        // -------------------------
        public List<ViewModel.Audio.Checked> controls_Checked { get; set; } = new List<ViewModel.Audio.Checked>()
        {
            new ViewModel.Audio.Checked() {  VBR = false },
        };

        // -------------------------
        // Enabled
        // -------------------------
        public List<ViewModel.Audio.Enabled> controls_Enabled { get; set; } = new List<ViewModel.Audio.Enabled>()
        {
            new ViewModel.Audio.Enabled()
            {
                Quality =           true,
                CompressionLevel =  false,
                VBR =               false,
                SampleRate =        true,
                BitDepth =          true,
            },
            
            // All other controls are set through Format.Controls.MediaTypeControls()
        };

    }

}
